﻿using DotNetExtensions.AspNet;
using Habi.Solver.Common;
using Habi.Solver.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Habi.Solver
{
    public class AppEnvironment : Singleton<AppEnvironment>
    {
        public readonly string OSName;
        public readonly string OSVersion;
        public readonly string Mac;
        public readonly string IPAddress;
        public readonly string DriveSize;

        public readonly string DownloadPath;
        public readonly string UploadServerUrl;

        public readonly LoginUserData User;
        private readonly IDeviceService device;
        private AppEnvironment()
        {
            DownloadPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Downloads");
            UploadServerUrl = "https://localhost:44386/api/file/Upload";
            User = new LoginUserData();
            device = new DeviceService();

            #region Initialize device infos

            var drive = device.FirstDrive();
            var network = device.FirstNetWork();
            var os = device.GetOsInfo();

            OSName = os.Name;
            OSVersion = os.Version;

            DriveSize = drive.Size;

            IPAddress = network.IPAddress;
            Mac = network.Mac;

            #endregion
        }
    }

    public class LoginUserData
    {
        public long Id { get; set; }
        public string Name { get; set; }

        public DateTime? LastLoginTime { get; set; }

        public bool IsLogin { get; set; } = false;

        public string Token { get; set; }


        public void Update(long id, string name)
        {
            Id = id;
            Name = name;
            IsLogin = true;
            LastLoginTime = DateTime.Now;
        }

        public void Update(long id, string name,string token)
        {
            Id = id;
            Name = name;
            IsLogin = true;
            LastLoginTime = DateTime.Now;
            Token = token;


        }
    }
}
